package service;

import mapper.SimpleStrategyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import po.Result;
import po.SimpleStrategy;

import java.util.List;

@Service
public class SimpleStrategyServiceImpl implements SimpleStrategyService {
    @Autowired
    private SimpleStrategyMapper simpleStrategyMapper;

    @Override
    public List<SimpleStrategy> findAllSimpleStrategies() throws Exception {
        return simpleStrategyMapper.findAllSimpleStrategies();
    }

    @Override
    public Result addSimpleStrategy(SimpleStrategy simpleStrategy) {
        Result result = new Result();
        try {
            simpleStrategyMapper.addSimpleStrategy(simpleStrategy);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("添加失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("添加成功！");
        return result;
    }

    @Override
    public Result deleteSimpleStrategyById(int id) {
        Result result = new Result();
        try {
            simpleStrategyMapper.deleteSimpleStrategyById(id);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("删除失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("删除成功！");
        return result;
    }

    @Override
    public Result updateSimpleStrategyById(int id, SimpleStrategy simpleStrategy) {
        Result result = new Result();
        try {
            simpleStrategy.setId(id);
            simpleStrategyMapper.updateSimpleStrategyById(simpleStrategy);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("修改失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("修改成功！");
        return result;
    }
}
